<?php
/**
 * Copyright 2011  SURFfoundation
 * 
 * This file is part of ESCAPE.
 * 
 * ESCAPE is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * ESCAPE is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with ESCAPE.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * For more information:
 * http://escapesurf.wordpress.com/
 * http://www.surffoundation.nl/
 * 
 * Contact: d.vierkant@utwente.nl
 * 
 * @license http://www.gnu.org/licenses/gpl.html GNU GPLv3
 */
?>
<?php
	/* @var $repository escape_repository_Repository */
	$repository =& $this->requestAttributes['repository'];
	/* @var $repositoryUi escape_repositoryui_RepositoryUi */
	$repositoryUi =& $this->requestAttributes['repositoryUi'];
	/* @var $users array */
	$users =& $this->requestAttributes['users'];
	
	$templateVariables = array();
	$templateVariables['title'] = 'Manage users';
	$this->requestAttributes['templateVariables'] =& $templateVariables;
?>
<?php $this->displayHeader(); ?>

<div class="escape_Section">

<div class="escape_SectionTitle">Manage users</div>

<p>
<a href="<?php print htmlspecialchars($repositoryUi->getActionLinkById('me'))?>">Back</a>
</p>

<?php
	if($repository->config['localauthn_enabled'])
	{
?>
<p id="escape_createUserClosed">
<a href="#" onclick="$('escape_createUserOpened').show(); $('escape_createUserClosed').hide(); return false">Create a new user</a>
</p>

<div id="escape_createUserOpened" class="escape_Selection" style="display: none">
<div class="escape_SectionTitle">Create a new user</div>

<form method="post" action="adminCreateUser" autocomplete="off">
<input type="hidden" name="verb" value="create" />

<table class="escape_FormTable">
<tr>
<td>
User ID:
</td>
<td>
<input type="text" name="userid" value="<?php print htmlspecialchars($userId); ?>" />
</td>
</tr>
<tr>
<td>
Full name:
</td>
<td>
<input type="text" name="fullname" value="<?php print htmlspecialchars($fullname); ?>" />
</td>
</tr>
<tr>
<td>
Email:
</td>
<td>
<input type="text" name="email" value="<?php print htmlspecialchars($email); ?>" />
</td>
</tr>
<tr>
<td>
Password:
</td>
<td>
<input type="password" name="password" value="" />
</td>
</tr>
</table>

<input type="submit" value="Create user" />
<input type="button" value="Cancel" onclick="this.form.reset(); $('escape_createUserClosed').show(); $('escape_createUserOpened').hide(); return false" />

</form>
</div>
<?php
	}
?>


<script type="text/javascript">
	jQuery(document).ready(function() {
		jQuery('#escape_userTable').dataTable({
			"sPaginationType": "full_numbers",
			"iDisplayLength": 25,
			"aaSorting": [[ 2, "asc"]]
		});
	} );
</script>

<table cellpadding="0" cellspacing="0" border="0" class="display" style="font-size: 85%" id="escape_userTable">
	<thead>
		<tr>
			<th></th>
			<th>ID</th>
			<th>Name</th>
			<th>Organization</th>
			<th>E-mail</th>
			<th>System roles</th>
		</tr>
	</thead>
	<tbody>
<?php
	foreach($users as $user)
	{
		/* @var $user escape_repository_User */
?>
		<tr>
			<td class="escape_Actions" style="white-space: nowrap;">
				<a href="<?php print htmlspecialchars($repositoryUi->getActionLinkById('adminEditUser', $user->getId())); ?>"><img src="/rsc/img/edit.gif" alt="Edit" /></a>
				<a href="<?php print htmlspecialchars($repositoryUi->getActionLinkById('adminDeleteUser', $user->getId())); ?>"><img src="/rsc/img/delete.gif" alt="Delete" /></a>
			</td>
			<td>
				<?php print htmlspecialchars($user->getId()); ?>
			</td>
			<td>
				<?php print htmlspecialchars($user->getName()); ?>
			</td>
			<td>
				<?php print htmlspecialchars($user->getOrganization()); ?>
			</td>
			<td>
				<?php print htmlspecialchars($user->getMbox()); ?>
			</td>
			<td>
				<?php print htmlspecialchars(implode(', ', $user->getSystemRoles(true))); ?>
			</td>
		</tr>
<?php
	}
?>
	</tbody>
	<tfoot>
		<tr>
			<th></th>
			<th>ID</th>
			<th>Name</th>
			<th>Organization</th>
			<th>E-mail</th>
			<th>System roles</th>
		</tr>
	</tfoot>
</table>

</div>

<?php $this->displayFooter(); ?>
